package com.flyco.pageindicator.anim.base;

import ohos.agp.animation.Animator;
import ohos.agp.components.Component;

/**
 * Indicator要执行的动画基类
 */
public abstract class IndicatorBaseAnimator {

    private Animator anim;

    /**
     * 由子类实现，通过控件获取需要执行的动画类
     *
     * @param component 要执行动画的控件
     * @return 控件要执行的动画
     */
    public abstract Animator setAnimation(Component component);

    private void start(final Component component) {
        reset(component);
        anim = setAnimation(component);
        if (anim != null) {
            anim.start();
        }
    }

    /**
     * 将控件状态重置
     *
     * @param component 要重置状态的控件
     */
    public static void reset(Component component) {
        component.setAlpha(1);
        component.setScale(1, 1);
        component.setTranslation(0, 0);
        component.setRotation(0);
    }

    /**
     * 给控件执行动画
     *
     * @param component 要执行动画的控件
     */
    public void playOn(Component component) {
        start(component);
    }

}
